package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.CommodityCatalog;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.ICommodityCatalogService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("commodityCatalog")
public class CommodityCatalogController {

    @Autowired
    private ICommodityCatalogService commodityCatalogService;
    @RequestMapping("list")
    public String list(@ModelAttribute("qo")QueryObject qo, Model model){
        model.addAttribute("pageInfo",commodityCatalogService.query(qo));
        return "commodity/catalog";
    }

    @RequestMapping("delete")
    @ResponseBody
    public JSONResult delete(Long id){
        commodityCatalogService.delete(id);
        return new JSONResult();
    }

    @RequestMapping("save")
    @ResponseBody
    public Object save(CommodityCatalog commodityCatalog) {
        JSONResult jsonResult = new JSONResult();
        try{
            commodityCatalogService.save(commodityCatalog);
        }catch (Exception e){
            return jsonResult.mark(e.getMessage());
        }
        return jsonResult; //象征性返回操作成功
    }
}
